package com.young.jpademo2.filter;


import com.young.jpademo2.rsa.RsaTest;
import com.young.jpademo2.rsa1.RsaTest1;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyInterceptor implements HandlerInterceptor {
    /*
     * 进入Controller层之前拦截请求，默认是拦截所有请求
     * @return 是否拦截当前请求，true表示拦截当前请求，false表示不拦截当前请求
     * @throws Exception 可能出现的异常
     * */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("--------jin ru preHandle-------------------");
       /* String encryptData=request.getParameter("encryptData");
        //String encryptData=request.getParameterValues("encryptData");
        //String  encryptData=(String)request.getAttribute("encryptData");
        System.out.println("encryptData"+encryptData);
        RsaTest rsaTest=new RsaTest();
        rsaTest.createKey();
        String data=encryptData;
        //客户端加密
        byte[] bytes=rsaTest.webEncrypt(data);
        //服务端解密
        String result=rsaTest.serverDecr(bytes);
        RsaTest1 rsaTest1=new RsaTest1();
        rsaTest1.createKey();
        //服务端加密
        byte[] bytes2=rsaTest1.serEncrypt(result);
        System.out.println("加密的byte:"+bytes2);*/

       /* public byte[] serverResult(Str){
            byte[] result=bytes2;
            return result;
        }*/


        return true;
    }
    // 处理完请求后但还未渲染试图之前进行的操作
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("----------jin ru postHandle----------------");
        /*public byte[] serverResult(){
            byte[] result=bytes2;
            return result;
        }*/

    }
    // 视图渲染后但还未返回到客户端时的操作
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("-----------jin ru afterCompletion----------");
    }
}